<template>
  <div class="comment-reply">
    <!-- 导航栏 -->
    <van-nav-bar
      :title="
        comment.reply_count
          ? comment.reply_count + '条评论回复'
          : '暂无评论回复'
      "
    >
      <van-icon slot="left" name="cross" @click="$emit('click-close')" />
    </van-nav-bar>
    <!-- /导航栏 -->

    <!-- 当前评论项 -->
    <div class="scroll-wrap">
      <comment-item :comment="comment" />
      <!-- /当前评论项 -->
      <van-cell title="全部评论"></van-cell>

      <!-- 评论的回复列表 -->

      <ArticleComment
        :source="comment.com_id"
        type="c"
        :list="commentList"
      ></ArticleComment>
    </div>
    <!-- /评论的回复列表 -->

    <!-- 发布评论 -->
    <!-- 发布评论 -->
    <van-popup v-model="isPostShow" position="bottom" style="height: 20%">
      <CommentPost :target="comment.com_id" @onpost-success="onPostSuccess" />
    </van-popup>
    <!-- /发布评论 -->
    <!-- 发布评论 -->
    <!-- 底部 -->
    <!-- 底部区域 -->
    <div class="reply-bottom">
      <van-button
        class="write-btn"
        size="small"
        round
        @click="isPostShow = true"
        >写评论</van-button
      >
    </div>

    <!-- /底部 -->
  </div>
</template>

<script>
import ArticleComment from "./article-comment.vue";
import CommentItem from "./comment-item.vue";
import CommentPost from "./CommentPost.vue";
export default {
  name: "CommentReply",
  components: {
    ArticleComment,
    CommentItem,
    CommentPost,
  },
  props: {
    comment: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isPostShow: false,
      commentList: [],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onPostSuccess(res) {
      console.log("最新评论的内容是", res);
      this.isPostShow = false;
      this.commentList.unshift(res.data.data.new_obj);
    },
  },
};
</script>

<style lang='less' scoped>
.comment-reply {
  .scroll-wrap {
    position: fixed;
    top: 92px;
    left: 0;
    right: 0;
    bottom: 88px;
    overflow-y: auto;
  }

  .reply-bottom {
    /* border: 1px solid green; */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    border-top: 1px solid #d8d8d8;

    .write-btn {
      width: 60%;
      border: 1px solid green;
      color: green;
    }
  }
  .van-popup {
    .comment-post {
      padding-top: 60px;
      padding-bottom: 20px;
    }
  }
}
</style>
